package org.kabeja.parser.table;

import org.kabeja.dxf.DXFConstants;
import org.kabeja.dxf.entity.DXFViewport;
import org.kabeja.parser.DXFValue;

/**
 * @author shutao
 * @since 2022/4/25 14:19
 */
public class DXFVPortTableHandler extends AbstractTableHandler {
    public static final int GROUPCODE_VPORT_NAME = 2;
    public static final int GROUPCODE_VPORT_LOWER_LEFT_X = 10;
    public static final int GROUPCODE_VPORT_LOWER_LEFT_Y = 20;
    public static final int GROUPCODE_VPORT_UPPER_RIGHT_X = 11;
    public static final int GROUPCODE_VPORT_UPPER_RIGHT_Y = 21;
    public static final int GROUPCODE_VPORT_CENTER_POINT_X = 12;
    public static final int GROUPCODE_VPORT_CENTER_POINT_Y = 22;
    public static final int GROUPCODE_VPORT_SNAP_BASE_POINT_X = 13;
    public static final int GROUPCODE_VPORT_SNAP_BASE_POINT_Y = 23;
    public static final int GROUPCODE_HEIGHT = 40;
    public static final int GROUPCODE_ASPECT_RATIO = 41;
    private DXFViewport viewport;

    public DXFVPortTableHandler() {
    }

    @Override
    public void endParsing() {
        this.doc.addDXFViewport(this.viewport);
    }

    @Override
    public String getTableKey() {
        return DXFConstants.TABLE_KEY_VPORT;
    }

    @Override
    public void parseGroup(int var1, DXFValue var2) {
        switch(var1) {
            case GROUPCODE_VPORT_NAME:
                this.viewport.setViewportID(var2.getValue());
                if ("*active".equalsIgnoreCase(var2.getValue())) {
                    this.viewport.setActive(true);
                }
                break;
            case GROUPCODE_VPORT_LOWER_LEFT_X:
                this.viewport.getLowerLeftCorner().setX(var2.getDoubleValue());
                break;
            case GROUPCODE_VPORT_CENTER_POINT_X:
                this.viewport.getCenterPoint().setX(var2.getDoubleValue());
                break;
            case GROUPCODE_VPORT_LOWER_LEFT_Y:
                this.viewport.getLowerLeftCorner().setY(var2.getDoubleValue());
                break;
            case GROUPCODE_VPORT_CENTER_POINT_Y:
                this.viewport.getCenterPoint().setY(var2.getDoubleValue());
                break;
            case GROUPCODE_HEIGHT:
                this.viewport.setHeight(var2.getDoubleValue());
                break;
            case GROUPCODE_ASPECT_RATIO:
                this.viewport.setAspectRatio(var2.getDoubleValue());
                break;
            default:
                break;
        }

    }

    @Override
    public void startParsing() {
        this.viewport = new DXFViewport();
    }
}